package com.campus.mapper;

import com.campus.annotation.AutoFill;
import com.campus.enumeration.OperationType;
import com.campus.pojo.dto.HomeworkDTO;
import com.campus.pojo.dto.HomeworkPageQueryDTO;
import com.campus.pojo.entity.Homework;
import com.campus.pojo.vo.HomeworkVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface HomeworkMapper {
    Page<HomeworkVO> pageQuery(HomeworkPageQueryDTO homeworkPageQueryDTO);

    void deleteByIds(List<Long> ids);

    @Insert("insert into homework(title,content,course_id,creator_id,deadline,status,create_time,update_time) values(#{title},#{content},#{courseId},#{creatorId},#{deadline},#{status},#{createTime},#{updateTime})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Homework homework);

    @AutoFill(value = OperationType.UPDATE)
    void update(Homework homework);

    @Select("select * from homework where id = #{id}")
    HomeworkVO getById(Long id);

    /**
     * 查询已发布并且截止时间小于24小时的作业
     * @param threshold
     * @return
     */
    @Select("select * from homework where status = 0 and deadline < #{threshold}")
    List<Homework> getUrgentHomeworkList(LocalDateTime threshold);
}
